<%@page import="dashboard.Statistics"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*"%>

<% %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>LeaderBoard</title>

</head>


<body>
	<div id="main">
		<%@include file="header.jsp"%>
		<%
		String error = (String) session.getAttribute("error");
		if (error != null) {
					%>

		<div id=error>
			<p class="warning">
				An error occurred:
				<%
						%><%=error%><br>
				
			</p>
		</div>
		<%
		}
		%>
		<!-- BEGIN KEUZEMENU -->

		<% 
		User currentUser2= (User) session.getAttribute("user");
		if(currentUser2==null){
	response.sendRedirect("login.jsp");
}
else{
	String type = (String) request.getParameter("type");
if(type==null){
 %>
		<fieldset>
			<legend> LeaderBoard</legend>
			<form name="getStatistics" method="post" action="Leaderboard">
		
				<div class="button">
				
			<button  style="width: 100%; text-align: center" name="type" value="allBoard" type="submit">Total Hours of Activity</button>
			<button  style="width: 100%; text-align: center" name="type" value="allPages" type="submit">Tracked Pages</button>
		 	<button  style="width: 100%; text-align: center" name="type" value="milestonesBoard" type="submit">Total achieved Milestones</button>
		 	<button  style="width: 100%; text-align: center" name="type" value="relativeAllPages" type="submit">Pages To Hours Ratio</button>

				</div>
				
			</form>
			
			<br>
			<br>
			<form method="post" action="dashboard.jsp" name="backMenu">
				<div class="button">
					<input type="submit" value="Back" name="back">
				</div>
			</form>
			

		</fieldset>
		
		
	<%	
 }
			
else if	(type.equals("allBoard") && session.getAttribute("allBoard")!=null){
	Map<String, Double> allBoard = (Map<String, Double>) session.getAttribute("allBoard");
	double ownValue = (Double) session.getAttribute("ownValue");
	int ownPosition = (Integer) session.getAttribute("ownPosition");
	ArrayList<String> favourites = (ArrayList<String>)session.getAttribute("favourites");
	Map<Integer,Long> favouritesBoard = (Map<Integer, Long>) session.getAttribute("favouritesBoard");
	String sort="Total hours of Activitvity";
	session.setAttribute("sort",sort);
%>

	<fieldset>
			<legend> LeaderBoard : Total activity
			
			<%if(session.getAttribute("course")!=null){%> for 
			<%=(String) session.getAttribute("course")%>
			<%} %>
			</legend>
			<div class="button">
	View by course<br>
	<form method="post" action="Leaderboard" name="allboardPercourse">
	<input type="hidden" name="type" value="courseBoard">
	<select style="width: 100%; text-align: center; height: 25px; font-size: 20px;" name="course">
	<%
	List<Long> courses = currentUser.getCourses();
	for(Long courseId: courses){
		String courseName =CourseRegistry.getInstance().getCourseName(courseId);
		%>
<option><%=courseName%></option>
		<%
	}
	%>
	</select>
	<input type="submit" value="Go">
	</form></div>
	

	<%@ include file="../charts/leaderboardTable.jsp"%>
		<div class="button"><form method="post" action="leaderboard.jsp"><input type="submit" value="Back"></input></form></div>
	</fieldset> <%
	
}

else if(type.equals("allPages") && session.getAttribute("allBoard")!=null){
	Map<String, Double> allBoard = (Map<String, Double>) session.getAttribute("allBoard");
	double ownValue = (Double) session.getAttribute("ownValue");
	int ownPosition = (Integer) session.getAttribute("ownPosition");
	ArrayList<String> favourites = (ArrayList<String>)session.getAttribute("favourites");
	Map<Integer,Long> favouritesBoard = (Map<Integer, Long>) session.getAttribute("favouritesBoard");
	String sort="Total pages studied";
	session.setAttribute("sort",sort);
%>

	<fieldset>
			<legend> LeaderBoard : Total pages studied
		<%if(request.getParameter("course")!=null){%> for 
			<%=(String) request.getParameter("course")%>
			<%} %>
			</legend>
			</legend>
			<div class="button">
	<form method="post" action="Leaderboard" name="allPagesPerCourse">
	<input type="hidden" name="type" value="coursePages">
	<select style="width: 100%; text-align: center; height: 25px; font-size: 20px;" name="course">
	<%
	List<Long> courses = currentUser.getCourses();
	for(Long courseId: courses){
		String courseName =CourseRegistry.getInstance().getCourseName(courseId);
		%>
<option><%=courseName%></option>
		<%
	}
	%>
	</select>
	<input type="submit" value="Go">

	</form></div>

	<%@ include file="../charts/leaderboardTable.jsp"%>
		<div class="button"><form method="post" action="leaderboard.jsp"><input type="submit" value="Back"></input></form></div>
	</fieldset> <%
	
}
			
else if(type.equals("milestonesBoard") && session.getAttribute("allBoard")!=null ){
	Map<String, Double> allBoard = (Map<String, Double>) session.getAttribute("allBoard");
	double ownValue = (Double) session.getAttribute("ownValue");
	int ownPosition = (Integer) session.getAttribute("ownPosition");
	ArrayList<String> favourites = (ArrayList<String>)session.getAttribute("favourites");
	Map<Integer,Long> favouritesBoard = (Map<Integer, Long>) session.getAttribute("favouritesBoard");
	String sort="Achieved milestones";
	session.setAttribute("sort",sort);
%>

	<fieldset>
			<legend> LeaderBoard : Achieved milestones</legend>
	<%@ include file="../charts/leaderboardTable.jsp"%>
		<div class="button"><form method="post" action="leaderboard.jsp"><input type="submit" value="Back"></input></form></div>
	</fieldset> <%
}
else if(type.equals("relativeAllPages")&& session.getAttribute("allBoard")!=null){
	Map<String, Double> allBoard = (Map<String, Double>) session.getAttribute("allBoard");
	double ownValue = (Double) session.getAttribute("ownValue");
	int ownPosition = (Integer) session.getAttribute("ownPosition");
	ArrayList<String> favourites = (ArrayList<String>)session.getAttribute("favourites");
	Map<Integer,Long> favouritesBoard = (Map<Integer, Long>) session.getAttribute("favouritesBoard");
	String sort="Pages to Hours studied Ratio";
	session.setAttribute("sort",sort);
%>

	<fieldset>
			<legend> LeaderBoard : Average amount pages/hour
			
				<%if(request.getParameter("course")!=null){%> for 
			<%=(String) request.getParameter("course")%>
			<%} %>
			</legend>
			<div class="button">
	View by course<br>
	<form method="post" action="Leaderboard" name="courseAllPages">
	<input type="hidden" name="type" value="courseAllPages">
	<select style="width: 100%; text-align: center; height: 25px; font-size: 20px;" name="course">
	<%
	List<Long> courses = currentUser.getCourses();
	for(Long courseId: courses){
		String courseName =CourseRegistry.getInstance().getCourseName(courseId);
		%>
<option><%=courseName%></option>
		<%
	}
	%>
	</select>
	<input type="submit" value="Go">
	</form></div>

	<%@ include file="../charts/leaderboardTable.jsp"%>
		<div class="button"><form method="post" action="leaderboard.jsp"><input type="submit" value="Back"></input></form></div>
	</fieldset> <%
}
			
else{
	response.sendRedirect("leaderboard.jsp?error");
}
			


}
session.removeAttribute("error");
session.removeAttribute("course");
session.removeAttribute("allBoard");
session.removeAttribute("ownPosition");
session.removeAttribute("ownValue");
session.removeAttribute("favouritesBoard");
session.removeAttribute("favourites");
session.removeAttribute("favourites");
%>

</div>
</body></html>
